// .........................................................................
// Title: plot_estimates.do
//
// Plots estimates from both security-level and firm-level regressions.
// .........................................................................

* ---------------------------------------
* Regression robustness estimates
* ---------------------------------------

* Load data
use "$tmp/ols_robustness_estimates", replace
rename index treat
rename beta b

* Confidence intervals
gen b_min = b - 1.96 * se
gen b_max = b + 1.96 * se

* Plotting order
gen order = .
replace order = 1 if treat == "baseline"
replace order = 2 if treat == "duration_1y"
replace order = 3 if treat == "bond_age"
replace order = 4 if treat == "reg_144a"
replace order = 5 if treat == "underwriters"
replace order = 6 if treat == "covenants"
replace order = 7 if treat == "drop_zeros"
replace order = 8 if treat == "no_aig"
replace order = 9 if treat == "no_hedging"
replace order = 10 if treat == "fixed_window"
replace order = 11 if treat == "no_trade_gaps"
replace order = 12 if treat == "drop_callables"
replace order = 13 if treat == "fin_util"
replace order = 14 if treat == "betas"
sort order

* Compose and output the plot (Figure 3)
scatter b order if treat == "baseline", mcolor(red) ///
    || rcap b_min b_max order if treat == "baseline", lcolor(red) ///
    || scatter b order if treat != "baseline", ///
    graphregion(color(white)) xtitle("") ///
    yline(0, lcolor(black)) ylab(.1(-.1)-.8) ytitle("Estimated Beta" " ") ///
    xsize(12) mcolor(blue) || rcap b_min b_max order if treat != "baseline", legend(off) lcolor(blue) ///
    xlab(.5 " " 1 `""Baseline" "(Full FE)" "' 2 `""Duration," "1Y Categ." "' ///
         3 `""Bond Age," "1Y Categ." "' 4 "144A" 5 "Underwriters" 6 "Covenants" 7 `""Drop" "Zeros" "' ///
         8 `""Exclude" "AIG" "' 9 `""Raw" "Returns" "' 10 `""Fixed" "Window" "' ///
         11 `""No Trade" "Gaps" "' 12 `""No" "Callables" "' ///
         13 `""No Fin.," "Utilities" "' 14 `""Beta" "Controls" "' 14.5 " ", labsize(medsmall)) ///
    xline(1.5, lcolor(black) lpattern(dash)) xline(6.5, lcolor(black) lpattern(dash)) ///
    text(.06 4 "Additional Interactions", color(gray)) ///
    text(.06 10.5 "Alternative Treatments and Specifications", color(gray)) ///
    text(-.05 1 "(1)", color(gray)) text(-.05 2 "(2)", color(gray)) text(-.05 3 "(3)", color(gray)) ///
    text(-.05 4 "(4)", color(gray)) text(-.05 5 "(5)", color(gray)) text(-.05 6 "(6)", color(gray)) ///
    text(-.05 7 "(7)", color(gray)) text(-.05 8 "(8)", color(gray)) text(-.05 9 "(9)", color(gray)) ///
    text(-.05 10 "(10)", color(gray)) text(-.05 11 "(11)", color(gray)) text(-.05 12 "(12)", color(gray)) ///
    text(-.05 13 "(13)", color(gray)) text(-.05 14 "(14)", color(gray)) 

graph export "$graphs/robustness.pdf", as(pdf) replace

* ---------------------------------------
* Investment dynamics estimates
* ---------------------------------------

* Load data
use "$tmp/investment_dynamics_estimates", clear

* Confidence intervals
gen beta_min = beta - 1.96 * sderr
gen beta_max = beta + 1.96 * sderr
gen beta_aqc_min = beta_aqc - 1.96 * se_aqc
gen beta_aqc_max = beta_aqc + 1.96 * se_aqc

* Add row for base year
local new = _N + 1
set obs `new'
replace year = 2007 if _n == _N
replace beta = 0 if _n == _N
replace beta_aqc = 0 if _n == _N
sort year

* Jitter x-values to space out plots
gen year1 = year + .05
gen year2 = year - .05

* Compose plot (Figure 10)
scatter beta year1, mcolor(red) ///
    || scatter beta_aqc year2, mcolor(blue) ///
    || line beta year1, lcolor(red%30) ///
    || line beta_aqc year2, lcolor(blue%30) ///
    || rcap beta_max beta_min year1, xline(2007) xtitle("") xlab(2004(1)2011) lcolor(red) yline(0) ylab(-.04(.02).08) ///
    || rcap beta_aqc_max beta_aqc_min year2, lcolor(blue) ///
        legend(order(1 2) label(1 "CAPX Over Assets") label(2 "CAPX and Acquisitions Over Assets")) ///
        ytitle("Investment Rate (%)") ylab(-.04 "-4%" -.02 "-2%" 0 "0%" .02 "2%" .04 "4%" .06 "6%" .08 "8%" .10 "10%") xsize(7.7)

graph export "$graphs/investment_dynamics.pdf", as(pdf) replace


* ---------------------------------------
* Offering dynamics estimates
* ---------------------------------------

* Estimates for new issuance
use "$tmp/issuance_dynamics_estimates", clear

* Add row for base year
local new = _N + 1
set obs `new'
replace year = 2007 if _n == _N
replace beta = 0 if _n == _N
replace sderr = 0 if _n == _N
sort year

* Confidence intervals
cap drop *max* *min*
gen beta_min = beta - 1.96 * sderr
gen beta_max = beta + 1.96 * sderr

* Plot for new issuance
scatter beta year, mcolor(red) || rcap beta_max beta_min year, yline(0) lcolor(red) legend(off) xtitle("") xlab(2004(1)2011) ///
    xline(2007) ylab(-.5(.25)1) || line beta year, lcolor(red%30) ytitle("Issuance Probability") xsize(5) saving("$tmp/new_issuance.gph", replace)

* Offering yield estimates
use "$tmp/offering_yield_dynamics_estimates", clear

* Add row for base year
local n_new = _N + 1
set obs `n_new'
replace year = 2007 if _n == _N
replace beta = 0 if _n == _N
replace sderr = 0 if _n == _N
sort year

* Confidence intervals
cap drop *max* *min*
gen beta_max = beta + 1.96 * sderr
gen beta_min = beta - 1.96 * sderr

* Plot for offering yields
scatter beta year, mcolor(blue) || rcap beta_max beta_min year, yline(0) lcolor(blue) legend(off) xtitle("") xlab(2004(1)2011) ///
    xline(2007) || line beta year, lcolor(blue%30) ytitle("Offering Yield (%)") xsize(5) ylab(-6 "-6%" -4 "-4%" -2 "-2%" 0 "0%" 2 "2%") ///
    saving("$tmp/offering_yields.gph", replace)

* Combine graphs (Figure 11)
gr combine "$tmp/new_issuance.gph" "$tmp/offering_yields.gph", cols(1) iscale(.95) xsize(7.5)
graph export "$graphs/offering_dynamics.pdf", as(pdf) replace
